package com.qfedu.controller;

import com.qfedu.dao.VipDao;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.User;
import com.qfedu.entity.Vip;
import com.qfedu.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class VipController {
    @Autowired
    private VipService vipService;
    @RequestMapping("/findAllVip")
    public ResponseData findAllVip(int page,int limit){
        return vipService.findAllVip(page, limit);
    }
    @RequestMapping("/addVip")
    public ResponseData addVip(Vip vip, HttpServletRequest request){

        ResponseData responseData = new ResponseData();
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginUser");
        vip.setuNo(user.getNo());
        boolean result = vipService.addVip(vip);
        if (result){
            responseData.setCode(ResponseData.SUCCESS_CODE);// 成功
            responseData.setMsg(ResponseData.SUCCESS_MSG);
        }else {
            responseData.setCode(ResponseData.FAIL_CODE);// 成功
            responseData.setMsg(ResponseData.FAIL_MSG);
        }
        return responseData;
    }


}
